home *** CD-ROM | disk | FTP | other *** search
/ PC Open 107 / PC Open 107 CD 1.bin / CD1 / INTERNET / COPIA SITI / Getleft / getleft-setup-notcl.exe / {app} / scripts / Opciones.tcl < prev    next >
Encoding:
Text File  |  2004-03-06  |  15.3 KB  |  394 lines

  1. ###############################################################################
  2. ###############################################################################
  3. ##                                Opciones.tcl
  4. ###############################################################################
  5. ###############################################################################
  6. ## Creates a dialog in which to choose the options for the program
  7. ###############################################################################
  8. ###############################################################################
  9. ## (c) 2001-2003 AndrΘs Garcφa Garcφa. fandom@retemail.es
  10. ## You may distribute the contents of this file under the terms of the GPL v2
  11. ###############################################################################
  12. ###############################################################################
  13.  
  14. namespace eval Opciones {
  15.  
  16. ###############################################################################
  17. # UpdateSpinBox
  18. #    Activates o deactivates the spinboxes.
  19. #
  20. # Parameter:
  21. #    which: The spinbox to update
  22. ###############################################################################
  23. proc UpdateSpinBox {which} {
  24.     variable window
  25.     variable optionsTemp
  26.  
  27.     if {$which=="internal"} {
  28.         if {$optionsTemp(limitLevels)==1} {
  29.             CuadroSpin::EnableSpin $window(intSpin) normal
  30.             if {$optionsTemp(levels)==0} {
  31.                 set optionsTemp(levels) 1
  32.             }
  33.         } else {
  34.             CuadroSpin::EnableSpin $window(intSpin) disable
  35.             set optionsTemp(levels) 0
  36.         }
  37.     } else {
  38.         if {$optionsTemp(external)==1} {
  39.             CuadroSpin::EnableSpin $window(extSpin) normal
  40.             if {$optionsTemp(exLevels)==0} {
  41.                 set optionsTemp(exLevels) 1
  42.             }
  43.         } else {
  44.             CuadroSpin::EnableSpin $window(extSpin) disable
  45.             set optionsTemp(exLevels) 0
  46.         }
  47.     }
  48.     return
  49. }
  50.  
  51. ###############################################################################
  52. # SetDefaultOptions
  53. #    This procedures set the downloading options to the default values.
  54. #
  55. # Parameter:
  56. #    The name of the options to set, it can be 'downOptions' or
  57. #    'downOptionsTemp'
  58. ###############################################################################
  59. proc SetDefaultOptions {optionsToSet} {
  60.     global defaultDownOptions
  61.  
  62.     upvar #0 $optionsToSet options
  63.     array set options [array get defaultDownOptions]
  64.  
  65.     if {$defaultDownOptions(levels)==-1} {
  66.         set options(limitLevels) 0
  67.     } else {
  68.         set options(limitLevels) 1
  69.     }
  70.     return
  71. }
  72.  
  73. ###############################################################################
  74. # SaveDefaultOptions
  75. #    Sets the current values of the options in the dialog as default.
  76. #############################################################################
  77. proc SaveDefaultOptions {} {
  78.     global defaultDownOptions
  79.     variable optionsTemp
  80.  
  81.     array set defaultDownOptions [array get optionsTemp]
  82.     if {$optionsTemp(limitLevels)==0} {
  83.         set defaultDownOptions(levels) -1
  84.     }
  85.     return
  86. }
  87.  
  88. ###############################################################################
  89. # ActivateMap
  90. #    It is invoked when the user clicks in the 'Get map' checkbutton in the
  91. #    options dialog.
  92. #
  93. # Side effects:
  94. #    It disables or activates the 'Only Html checkbutton' and the 'Choose
  95. #    filter' button, sets optionsTemp(onlyHtml) to '1' to get the map and
  96. #    to '0' not to get it.
  97. ###############################################################################
  98. proc ActivateMap {} {
  99.     variable optionsTemp
  100.     variable window
  101.  
  102.     if {$optionsTemp(map)==1} {
  103.         $window(onlyHtml)  configure -state disable
  104.         $window(chooseFil) configure -state disable
  105.         set optionsTemp(onlyHtml) 1
  106.     } else {
  107.         $window(onlyHtml)  configure -state normal
  108.         $window(chooseFil) configure -state normal
  109.         set optionsTemp(onlyHtml) 0
  110.     }
  111.  
  112.     return
  113. }
  114.  
  115. ###############################################################################
  116. # ChangeFilter
  117. #    Invokes the dialog to choose the filter for the download.
  118. #
  119. # Side effect:
  120. #    Puts the returned filter into 'optionsTemp(filter)'
  121. ###############################################################################
  122. proc ChangeFilter {} {
  123.     variable window
  124.     variable optionsTemp
  125.  
  126.     set optionsTemp(filter) [Herramientas::FilterFiles \
  127.             $optionsTemp(filter) $window(win)]
  128.  
  129.     return
  130. }
  131.  
  132. ###############################################################################
  133. # ChooseOptionsWindow
  134. #    Creates the dialog in which to select the different options.
  135. #
  136. # Parameters:
  137. #    parent: Path of the dialog over which this one will appear.
  138. ###############################################################################
  139. proc ChooseOptionsWindow {parent} {
  140.     global labelTitles labelButtons labelDialogs labelFrames getleftOptions
  141.     global dirGetleft indexButtons indexDialogs
  142.     variable optionsTemp
  143.     variable done
  144.     variable window
  145.  
  146.     set coord(x) [winfo rootx $parent]
  147.     set coord(y) [winfo rooty $parent]
  148.  
  149.     if {[winfo exists .optionsWin]} {
  150.         wm deiconify $window(win)
  151.         raise $window(win)
  152.         wm geometry $window(win) +[expr {$coord(x)+100}]+[expr {$coord(y)+15}]
  153.         return
  154.     } 
  155.  
  156.     set win [toplevel .optionsWin]
  157.     wm resizable $win 0 0
  158.     wm title $win $labelTitles(optionsWin)
  159.     wm geometry $win +[expr {$coord(x)+100}]+[expr {$coord(y)+15}]
  160.  
  161.     set extFrame  [frame $win.extFrame]
  162.     set intFrame  [frame $extFrame.intFrame]
  163.     set butFrame  [frame $extFrame.butFrame]
  164.  
  165.     set linkFrame [fl::FrameLabel $intFrame.links -bd 2 -relief groove         \
  166.             -textvariable labelFrames(links)]
  167.     set intLinks    [frame $linkFrame.int]
  168.     set updirLinks  [underButton::UnderButton $intLinks.updirLinks             \
  169.             -buttontype checkbutton -variable Opciones::optionsTemp(dir)       \
  170.             -textvariable labelDialogs(uplinks) -under $indexDialogs(uplinks)]
  171.     set updateLinks [underButton::UnderButton $intLinks.updateLinks            \
  172.             -buttontype checkbutton -under $indexDialogs(update)               \
  173.             -variable Opciones::optionsTemp(update)                            \
  174.             -textvariable labelDialogs(update)]
  175.     set cgiLinks    [underButton::UnderButton $intLinks.cgiLinks               \
  176.             -variable Opciones::optionsTemp(cgi) -buttontype checkbutton       \
  177.             -textvariable labelDialogs(cgi) -under $indexDialogs(cgi)]
  178.  
  179.     set levelFrame [fl::FrameLabel $intFrame.levels -bd 2 -relief groove       \
  180.             -textvariable labelFrames(levels)]
  181.     set intLevels  [frame $levelFrame.int]
  182.     set internal   [underButton::UnderButton $intLevels.internal               \
  183.             -variable Opciones::optionsTemp(limitLevels)                       \
  184.             -buttontype checkbutton  -under $indexDialogs(levels)              \
  185.             -textvariable labelDialogs(levels)                                 \
  186.             -command "Opciones::UpdateSpinBox internal"]
  187.     set external   [underButton::UnderButton $intLevels.external               \
  188.             -variable Opciones::optionsTemp(external) -buttontype checkbutton  \
  189.             -textvariable labelDialogs(external) -under $indexDialogs(external)\
  190.             -command "Opciones::UpdateSpinBox external"]
  191.     set intSpin [CuadroSpin::CuadroSpin $intLevels.intspin                     \
  192.             -default 0 -min 0 -max 5 -width 3                                  \
  193.             -bg $getleftOptions(bg)       -fg    $getleftOptions(fg)           \
  194.             -disbg $getleftOptions(disBg) -disfg $getleftOptions(disFg)        \
  195.             -textvariable Opciones::optionsTemp(levels)]
  196.     set extSpin [CuadroSpin::CuadroSpin $intLevels.extspin                     \
  197.             -default 0 -min 0 -max 3 -width 3                                  \
  198.             -bg $getleftOptions(bg)       -fg    $getleftOptions(fg)           \
  199.             -disbg $getleftOptions(disBg) -disfg $getleftOptions(disFg)        \
  200.             -textvariable Opciones::optionsTemp(exLevels)]
  201.  
  202.     set imageFrame   [fl::FrameLabel $intFrame.image   -bd 2 -relief groove    \
  203.             -textvariable labelFrames(images)]
  204.     set intImages    [frame $imageFrame.int]
  205.     set all          [underButton::UnderButton $intImages.all        -value 0  \
  206.             -textvariable labelDialogs(allImages)   -buttontype radiobutton    \
  207.             -under $indexDialogs(allImages)                                    \
  208.             -variable Opciones::optionsTemp(images)]
  209.     set onlyThumbs   [underButton::UnderButton $intImages.onlyThumbs -value 1  \
  210.             -variable Opciones::optionsTemp(images) -buttontype radiobutton    \
  211.             -under $indexDialogs(onlyThumb)                                    \
  212.             -textvariable labelDialogs(onlyThumb)]
  213.     set noThumbs     [underButton::UnderButton $intImages.noThumbs   -value 2  \
  214.             -variable Opciones::optionsTemp(images) -buttontype radiobutton    \
  215.             -textvariable labelDialogs(noThumb) -under $indexDialogs(noThumb)]
  216.     
  217.     set filterFrame  [fl::FrameLabel $intFrame.filters -bd 2 -relief groove    \
  218.             -textvariable labelFrames(filters)]
  219.     set intFilters   [frame $filterFrame.int]
  220.     set mapLinks     [underButton::UnderButton $intFilters.mapLinks            \
  221.             -textvariable labelDialogs(getMap)  -buttontype checkbutton        \
  222.             -variable Opciones::optionsTemp(map) -under $indexDialogs(map)     \
  223.             -command Opciones::ActivateMap -under $indexDialogs(getMap)]
  224.     set onlyHtml     [underButton::UnderButton $intFilters.onlyHtml            \
  225.             -variable Opciones::optionsTemp(onlyHtml) -buttontype checkbutton  \
  226.             -under $indexDialogs(onlyHtml) -textvariable labelDialogs(onlyHtml)]
  227.     set chooseFilter [underButton::UnderButton $intFilters.choose              \
  228.             -textvariable labelButtons(chooseFilter)   -buttontype button      \
  229.             -under $indexButtons(chooseFilter) -command Opciones::ChangeFilter]
  230.  
  231.     set accept  [underButton::UnderButton $butFrame.accept -width 8            \
  232.         -textvariable labelButtons(ok)     -buttontype button                  \
  233.         -under $indexButtons(ok)     -command "Opciones::ChooseOptionsControl"]
  234.     set cancel  [underButton::UnderButton $butFrame.cancel -width 8            \
  235.         -textvariable labelButtons(cancel)  -buttontype button                 \
  236.         -under $indexButtons(cancel) -command "set Opciones::done 0"]
  237.     set help    [underButton::UnderButton $butFrame.help -width 8              \
  238.         -textvariable  labelButtons(help)   -buttontype button                 \
  239.         -under $indexButtons(help)                                             \
  240.         -command "[list help::init [file join $dirGetleft(doc) help.help] howtoDown#Options]"]
  241.     set saveOps [underButton::UnderButton $butFrame.save -width 8              \
  242.         -textvariable labelButtons(save)    -buttontype button                 \
  243.         -under $indexButtons(save)   -command "Opciones::SaveDefaultOptions"]
  244.     set loadOps [underButton::UnderButton $butFrame.load -width 8              \
  245.         -textvariable labelButtons(load)    -buttontype button                 \
  246.         -under $indexButtons(load)                                             \
  247.         -command "
  248.                 Opciones::SetDefaultOptions Opciones::optionsTemp
  249.                 Opciones::ActivateMap
  250.                 Opciones::UpdateSpinBox internal
  251.                 Opciones::UpdateSpinBox external
  252.         "]
  253.  
  254.     set window(win)       $win
  255.     set window(intSpin)   $intSpin
  256.     set window(extSpin)   $extSpin
  257.     set window(onlyHtml)  $onlyHtml
  258.     set window(chooseFil) $chooseFilter
  259.  
  260.     if {$optionsTemp(map)==1} {
  261.         ActivateMap
  262.     }
  263.  
  264.     grid $extFrame -padx 5 -ipady 5
  265.     grid $intFrame -sticky s
  266.  
  267.     grid $linkFrame   $levelFrame $butFrame -padx 5 -pady 5 -sticky news
  268.     grid $filterFrame $imageFrame           -padx 5 -pady 5 -sticky news
  269.  
  270.     grid configure $butFrame -rowspan 2
  271.  
  272.     grid $intLinks          -sticky w -padx 5 -pady 5 
  273.     grid $updirLinks        -sticky w
  274.     grid $updateLinks       -sticky w
  275.     grid $cgiLinks          -sticky w
  276.  
  277.     grid $intLevels         -sticky w -padx 5 -pady 5 
  278.     grid $internal $intSpin -sticky w
  279.     grid $external $extSpin -sticky w
  280.  
  281.     grid $intFilters        -sticky w -padx 5 -pady 5  
  282.     grid $mapLinks          -sticky w
  283.     grid $onlyHtml          -sticky w
  284.     grid $chooseFilter  
  285.  
  286.     grid $intImages         -sticky w -padx 5 -pady 5
  287.     grid $all               -sticky w
  288.     grid $onlyThumbs        -sticky w
  289.     grid $noThumbs          -sticky w
  290.  
  291.     grid $accept  -pady 3
  292.     grid $cancel  -pady 3
  293.     grid $loadOps -pady 3
  294.     grid $saveOps -pady 3
  295.     grid $help    -pady 3
  296.  
  297.     focus $win
  298.     bind  $win <Escape> "set Opciones::done 0"
  299.  
  300.     return
  301. }
  302.  
  303. ###############################################################################
  304. # ChooseOptionsControl
  305. #    Makes sure that the options in the dialog make sense before closing.
  306. ###############################################################################
  307. proc ChooseOptionsControl {} {
  308.     global labelTitles labelMessages
  309.     variable window
  310.     variable done
  311.     variable optionsTemp
  312.  
  313.     if {$optionsTemp(limitLevels)==1} {
  314.         set intLimit $CuadroSpin::CuadroSpins($window(intSpin))
  315.         if {![regexp {^[0-9]+$} $intLimit]} {
  316.             tk_messageBox -title $labelTitles(error) -parent $window(win) \
  317.                     -message $labelMessages(intNaN)  -type ok 
  318.             return
  319.         }
  320.         if {$intLimit<0} {
  321.             CuadroSpin::CuadroSpins($window(intSpin)) 0
  322.         }
  323.         if {$intLimit>5} {
  324.             CuadroSpin::CuadroSpins($window(intSpin)) 5
  325.         }
  326.     }
  327.  
  328.     if {$optionsTemp(external)!=0} {
  329.         set extLimit $CuadroSpin::CuadroSpins($window(extSpin))
  330.         if {![regexp {^[0-9]+$} $extLimit]} {
  331.             tk_messageBox -title $labelTitles(error) -parent $window(win) \
  332.                     -message $labelMessages(extNaN)  -type ok 
  333.             return
  334.         }
  335.         if {$extLimit<0} {
  336.             CuadroSpin::CuadroSpins($window(intSpin)) 0
  337.         }
  338.         if {$extLimit>3} {
  339.             CuadroSpin::CuadroSpins($window(intSpin)) 3
  340.         }
  341.     }
  342.  
  343.     set done 1
  344.  
  345.     return
  346. }
  347.  
  348. ###############################################################################
  349. # ChooseOptions
  350. #    Selects the different options.
  351. #
  352. # Parameter:
  353. #    options: The array in which the options will be stored.
  354. #    parent: Path of the window over which the dialog will appear
  355. #
  356. # Return
  357. #    '1' if the user accepted the changes, '0' if he cancelled.
  358. ###############################################################################
  359. proc ChooseOptions {optionsArray {parent .}} {
  360.     variable optionsTemp
  361.     variable window
  362.     variable done
  363.  
  364.     upvar $optionsArray downOptions
  365.     catch {unset optionsTemp}
  366.  
  367.     array set optionsTemp [array get downOptions]
  368.     if {$optionsTemp(levels)==-1} {
  369.         set optionsTemp(limitLevels) 0
  370.         set optionsTemp(levels) 0
  371.     } else {
  372.         set optionsTemp(limitLevels) 1
  373.     }
  374.     
  375.     ChooseOptionsWindow $parent
  376.     UpdateSpinBox internal
  377.     UpdateSpinBox external
  378.     tkwait variable Opciones::done
  379.  
  380.     if {$done==1} {
  381.         array set downOptions [array get optionsTemp]
  382.         if {$optionsTemp(limitLevels)==0} {
  383.             set downOptions(levels) -1
  384.         } 
  385.     }
  386.  
  387.     catch {wm withdraw $window(win)}
  388.  
  389.     return $done
  390. }
  391.  
  392. }
  393.  
  394.